from app.extension.database.sqlalchemy import sqla_db as db
from datetime import datetime
from .base_model import BaseModel


class ProductModel(db.Model, BaseModel):

    """商品模型"""
    __tablename__ = 'tb_product'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), comment='商品名称')
    price = db.Column(db.Integer,  comment='价格 分')
    stock = db.Column(db.Integer, comment='库存')
    create_time = db.Column(db.DateTime, default=datetime.now)
    delete_time = db.Column(db.DateTime)
    imgs_id = db.Column(db.String(255), comment='商品的图片id 以|分隔')
    sell_count = db.Column(db.Integer, default=0, comment='商品卖出去的数量')
    summary = db.Column(db.String(50), comment='商品摘要')
    store_id = db.Column(db.Integer, comment='商品所属店铺')

    def __init__(self, data:dict, store_id):
        self.name = data.get('name')
        self.price = data.get('price')
        self.stock = data.get('stock')
        self.imgs_id = data.get('imgs_id')
        self.summary = data.get('summary')
        self.store_id = store_id
